home *** CD-ROM | disk | FTP | other *** search
/ BBS Toolkit / BBS Toolkit.iso / pc_board / rnet108u.zip / MAILRUN.SLT < prev    next >
Text File  |  1992-07-27  |  11KB  |  364 lines

  1. // ------------------------------------------------------------------------- //
  2. //
  3. //   PCBoard Mail Script (MAILDOOR.SLT) -- Handles the door and files;
  4. //   Login *MUST* be handled by the dialing dir script (PCBLOGIN.SLT)
  5. //
  6. //   Robert Vostreys, FTL Sysop, 404-292-8761, 404-299-3930 HST
  7. //
  8. //   Yeah, this script is a bit more complex than it needs to be, but I like
  9. //   to cover most (if not all) of the bases when doing automated things.
  10. //
  11. // ------------------------------------------------------------------------- //
  12. //
  13. //   NOTE: All references to HOST_ID should be replaced with the actual code
  14. //   (name) assigned to your host system's mail door.  Please contact your
  15. //   host to determine what their HOST_ID is.
  16. //
  17. //   Use this script to call and up/download QWK echomail to your host system.
  18. //   Copy (or rename) this script to HOST_ID.SLT.  You may leave this script
  19. //   as MAILRUN.SLT, in which case you will need to use CS MAILRUN to compile.
  20. //
  21. //   Edit the string values below to whatever is approperate (multiple dialing
  22. //   directory entries may be placed, as shown below).  The actual login to
  23. //   the host BBS MUST be handled by the autoscript entry in the dialing
  24. //   directory (see PCBLOGIN.SLT).
  25. //
  26. //   Compile this script with CS HOST_ID.SLT  (will produce HOST_ID.SLC) then
  27. //   place the resulting HOST_ID.SLC file where Telix.exe is kept.
  28. //
  29. // ------------------------------------------------------------------------- //
  30. //
  31. //   To execute a mailrun, start Telix with :  TELIX -sHOST_ID
  32. //   If you leave this script as MAILRUN.SLT:  TELIX -sMAILRUN
  33. //
  34. //   See the TELIX.DOC and SALT.DOC files for more information on programming
  35. //   with the SALT telix script language.
  36. //
  37. // ------------------------------------------------------------------------- //
  38.  
  39.    str  dlfilename[] = "e:\rnet\TRP.QWK";   // Used to check for existance...
  40.    str  ulfilename[] = "e:\rnet\TRP.REP";   // Used for filespec in UpLoad...
  41.    str  hostnumber[] = "33 34 35";          // Dialing Directory entries
  42.    str  newdlpath[]  = "e:\rnet\";          // Where to download the .QWK's to
  43.    int  reset_baud   = 19200;               // baud to reset after host hangup
  44.  
  45.    str holddowndir[80];
  46.  
  47. // ------------------------------------------------------------------------- //
  48.  
  49. main()
  50.  {
  51.  
  52.    holddowndir = _down_dir;      // change download directory so auto-zmodem
  53.    _down_dir   = newdlpath;      // downloads will work correctly.
  54.  
  55.    dial_host();                  // call host, login done by AutoScript
  56.                                  // in dialing directory (such as PCBLOGIN)
  57.  
  58.    get_to_prompt();              // get to maildoor command prompt
  59.  
  60.    get_mailpack();               // download any QWKs
  61.  
  62.    send_mailpack();              // upload any existing REPs
  63.  
  64.    logoff_host();                // goodbye from host, hangup
  65.  
  66.    off_line();                   // take the phone off-hook
  67.  
  68.    exitscript(0);                // exit Telix, errorlevel 0
  69.  
  70.  }
  71.  
  72. // ------------------------------------------------------------------------- //
  73.  
  74. dial_host()
  75.  {
  76.    clear_scr();
  77.    prints("Dialing Host...");
  78.  
  79.    cputs_tr("ATH0^M");
  80.    waitfor("OK", 5);
  81.    cputs_tr("AT^M");
  82.    waitfor("OK", 5);
  83.  
  84.    dial(hostnumber, 10, 0);
  85.    if (_entry_enum == 0)     exitscript(-2);
  86.    if (!carrier())           exitscript(-2);
  87.  }
  88.  
  89. // ------------------------------------------------------------------------- //
  90.  
  91. logoff_host()
  92.  {
  93.    int junk = 0;
  94.  
  95.    Get_Commandprompt();
  96.    terminal();
  97.    cputs("G^M");
  98.    terminal();
  99.  
  100.    status_wind("Goodbye...", 5);
  101.  
  102.    terminal();
  103.    delay(10);
  104.    terminal();
  105.    delay(10);
  106.    terminal();
  107.  }
  108.  
  109. // ------------------------------------------------------------------------- //
  110.  
  111. get_to_prompt()
  112.  {
  113.    int junk = 0;
  114.  
  115.    terminal();
  116.    status_wind("Waiting for door to open...", 20);
  117.    terminal();
  118.    delay(20);
  119.    terminal();
  120.    Get_Commandprompt(junk);
  121.  }
  122.  
  123. // ------------------------------------------------------------------------- //
  124.  
  125. get_mailpack()        // AUTO ZMODEM DOWNLOADS ASSUMED TO BE IN USE!
  126.  {
  127.    str buffer[80];
  128.    int tmark = 0;
  129.    int t1    = 0;
  130.    int t2    = 0;
  131.    int stat  = 0;
  132.  
  133.    if (carrier())
  134.     {
  135.       terminal();
  136.       if (filefind(dlfilename, 0, buffer))
  137.        {
  138.          buffer = "DEL ";
  139.          strcat(buffer, dlfilename);
  140.          dos(buffer, 0);
  141.          status_wind("KILL QWK...", 10);
  142.          terminal();
  143.        }
  144.  
  145.       status_wind("Request Download...", 5);
  146.       cputs("D^M");
  147.       terminal();
  148.       tmark = timer_start(9000);               //  wait up to 15 minutes for SCAN
  149.       t1  = track("Personal Messages", 1);     //  Rnet mail packet ready
  150.       t2  = track("no messages found", 1);     //  Rnet mail packet NOT READY
  151.  
  152.       while (carrier() and (!time_up(tmark)))
  153.        {
  154.          terminal();
  155.          stat = track_hit(0);
  156.          if (stat == t1)
  157.           {
  158.             cputs("Y^M");                      //  yes we want the mailpack
  159.             track_free(0);                     //  clear all track channels
  160.             timer_free(tmark);                 //  clear all timer channels
  161.             terminal();
  162.  
  163.             t1 = track(" Command?", 1);        //  look for prompt when done
  164.             tmark = timer_start(9000);         //  15 minutes allowed for DLing
  165.             terminal();
  166.  
  167.             while (carrier() and (!time_up(tmark)))
  168.              {
  169.                if (track_hit(0))  break;       //  at prompt... done
  170.                terminal();                     //  wait for download to finish
  171.              }
  172.  
  173.             terminal();
  174.             track_free(0);                     //  clear all track channels
  175.             timer_free(tmark);                 //  clear all timer channels
  176.             break;
  177.           }
  178.          else if (stat == t2)
  179.           {
  180.             status_wind("No QWK!", 5);
  181.             break;
  182.           }
  183.        }
  184.      status_wind("QWK transfer options completed!", 10);
  185.      terminal();
  186.    }
  187.  }
  188.  
  189. // ------------------------------------------------------------------------- //
  190.  
  191. send_mailpack()
  192.  {
  193.    str buffer[80];
  194.  
  195.    if (carrier())
  196.     {
  197.       if (!filefind(ulfilename, 0, buffer))   // check if we have REP to send
  198.        {
  199.          terminal();
  200.          return(0);                           // ...nope, get outta here.
  201.        }
  202.  
  203.       cputs("U^M");                           // ...yep, tell door to expect it
  204.       status_wind("Request Upload...", 5);
  205.       terminal();
  206.       if (!carrier())  return;
  207.  
  208.       if (send('Z', ulfilename) != 0)         // ZMODEM ASSUMED!
  209.        {
  210.          if (!carrier())  return();
  211.          clear_scr();
  212.          status_wind("KILL REP...", 10);
  213.          buffer = "DEL ";
  214.          strcat(buffer, ulfilename);
  215.          dos(buffer, 0);                      // delete REP packet
  216.          terminal();
  217.  
  218.          status_wind("Waiting for REP insert...", 30);
  219.          terminal();
  220.        }
  221.       terminal();
  222.    }
  223.  }
  224.  
  225. // ------------------------------------------------------------------------- //
  226.  
  227. exitscript(int flag)
  228.  {
  229.  
  230.   if (flag == -2)
  231.    {
  232.      status_wind("Connect NOT established!", 30);
  233.    }
  234.  
  235.   if (flag == -1)
  236.    {
  237.      status_wind("Door did NOT respond!", 30);
  238.    }
  239.  
  240.   off_line();
  241.   terminal();
  242.   _down_dir = holddowndir;
  243.  
  244.   if (flag == -1) ExitTelix(1);   // Door not available  (ErrorLevel == 1)
  245.   if (flag == -2) ExitTelix(2);   // No connection       (ErrorLevel == 2)
  246.   ExitTelix(0);                   // Normal Exit         (ErrorLevel == 0)
  247.  
  248.  }
  249.  
  250. // ------------------------------------------------------------------------- //
  251.  
  252. off_line()
  253.  {
  254.    status_wind("Waiting for 'NO CARRIER'...", 20);
  255.  
  256.    waitfor("NO CARRIER", 5);
  257.     terminal();
  258.     if (carrier())  hangup();
  259.  
  260.    delay(5);
  261.  
  262.    set_cparams(reset_baud, get_parity(), get_datab(), get_stopb());
  263.  
  264.    cputs_tr("AT^M");           // get modem attention
  265.    waitfor("OK", 5);
  266.     terminal();
  267.     delay(5);
  268.     terminal();
  269.  
  270.    cputs_tr("ATZ^M");          // reset modem to CMOS defaults
  271.    waitfor("OK", 5);
  272.     terminal();
  273.     delay(5);
  274.     terminal();
  275.  
  276.    cputs_tr("ATZ^M");          // Do it again -- in case RING came in...
  277.    waitfor("OK", 5);
  278.     terminal();
  279.     delay(5);
  280.  
  281.    cputs_tr("ATH1^M");         // Go off-hook
  282.    waitfor("OK", 3);
  283.     terminal();
  284.     delay(5);
  285.  
  286.    cputs_tr("ATH1^M");         // Again -- just in case a RING came in...
  287.    waitfor("OK", 3);
  288.     terminal();
  289.     terminal();
  290.  
  291.    status_wind("Line should now be off-hook.", 10);
  292.  
  293.    exittelix(0);               // Unload Telix, return to batch w/Errorlevel=0
  294.  }
  295.  
  296. // ------------------------------------------------------------------------- //
  297.  
  298. Get_Commandprompt()
  299.  {
  300.    int t1 = 0;
  301.    int t2 = 0;
  302.    int t3 = 0;
  303.    int t4 = 0;
  304.    int t5 = 0;
  305.    int stat = 0;
  306.    int statflag = 0;
  307.    int tmark = 0;
  308.    int ulflag = 0;
  309.  
  310.    t1  = track("mand?", 1);            // door command prompt
  311.    t2  = track("SUCCESSFULLY", 1);     // DL was successful
  312.    t3  = track(" to continue", 1);     // enter to continue
  313.    t4  = track("More:", 1);            // more prompt
  314.    t5  = track("(N)", 1);              // yipes, more more prompts!
  315.    tmark = timer_start(1800);          // wait up to 3 minutes for door
  316.  
  317.    cputs("^M");
  318.  
  319.    while (carrier())
  320.     {
  321.       terminal();
  322.  
  323.       stat = track_hit(0);                 // see if any track flags set
  324.       if (stat == t1)  break;              //  at Command? prompt
  325.       if (stat == t2)
  326.        {
  327.          ulflag = 1;
  328.          break;
  329.        }
  330.       if (stat == t3)                      // y/n/ns
  331.        {
  332.          cputs("^M");
  333.          terminal();
  334.          timer_restart(tmark, 1800);       // wait up to 3 minutes for door
  335.        }
  336.       if (stat == t4 or stat == t5)
  337.        {
  338.          cputs("N");
  339.          cputs("^M");
  340.          terminal();
  341.          delay(10);
  342.          terminal();
  343.        }
  344.       if (time_up(tmark))                   // check for no activity
  345.        {
  346.          status_wind("Wakeup!", 1);
  347.          cputs("^M");
  348.          terminal();
  349.          statflag = statflag + 1;
  350.          timer_restart(tmark, 1800);          // 3 minute checks now...
  351.          if (statflag > 10)  exitscript(-1);  // Up to 30 minutes to wakeup
  352.        }
  353.       if (statflag==2) break;
  354.     }
  355.  
  356.    track_free(0);                           // Clear all track channels
  357.    timer_free(tmark);                       // Clear all timer channels
  358.  
  359.    return(ulflag);
  360.  }
  361.  
  362. // ------------------------------------------------------------------------- //
  363.  
  364.